%by clq
%2021/6/12
function [i_RP, profits_RP] = round_robin_pref(j_all, pref)
   addpath functions;
   global I J P CURRENT
   %j_all is the given order of patient types
   N = size(j_all, 2);
   S = zeros(I,J);
   i_RP = zeros(1, N);
   profits_RP = zeros(1, N);
   %Step1:decide the preference randomly, and then find the optimal slot for each patient
   j = 0; k = 0;
   Q = ones(I, 1);

   for n = 1:N
      pref_temp = pref(n);
      if pref_temp == 1
         j = j + 1;
         i_RP(n) = mod(j-1, I/2) + 1;
      else
         k = k + 1;
         i_RP(n) = mod(k-1, I/2) + 5;
      end
   end
   %Step2:find the profit after each patient is assigned
   for n = 1:N
      Q = [Q, zeros(I,1)];
      j = j_all(n);
      S(i_RP(n), j) = S(i_RP(n), j) + 1;
         CURRENT = n;
         Q = findQ2(Q, i_RP(1, n), j, P, n); 
         R = findR(Q);
         profits_RP(n) = function_fQR2(Q, R);
   end
